home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / DataScope 2.0.3 / DataScope2l / HDFpartial / dfi.h < prev   
Encoding:
C/C++ Source or Header  |  1994-05-04  |  14.6 KB  |  394 lines  |  [TEXT/????]

  1. /*****************************************************************************
  2. *              NCSA HDF version 3.00
  3. *                December, 1989
  4. *
  5. * NCSA HDF Version 3.00 source code and documentation are in the public
  6. * domain.  Specifically, we give to the public domain all rights for future
  7. * licensing of the source code, all resale rights, and all publishing rights.
  8. * We ask, but do not require, that the following message be included in all
  9. * derived works:
  10. * Portions developed at the National Center for Supercomputing Applications at
  11. * the University of Illinois at Urbana-Champaign.
  12. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  13. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  14. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  15. *****************************************************************************/
  16.  
  17. /*-----------------------------------------------------------------------------
  18.  * File:    dfi.h
  19.  * Purpose: HDF internal header file
  20.  * Invokes: stdio.h, sys/file.h
  21.  * Contents: 
  22.  *  Compilation parameters
  23.  *  Machine-dependent definitions
  24.  *  Flexibility definitions: i/o buffering, dynamic memory, structure i/o
  25.  *  Size parameters
  26.  * Remarks: To port to a new system, only dfi.h and Makefile need be modified.
  27.  *          This file is included with user programs, but users do not see it.
  28.  *---------------------------------------------------------------------------*/
  29.  
  30.  
  31. #ifndef DF_MAGICK        /* avoid re-inclusion */
  32.  
  33. #define    DF_MAGICK    "\016\003\023\001" /* ^N^C^S^A */
  34.  
  35. #ifndef FILE
  36. #include <stdio.h>
  37. #endif /*FILE*/
  38.  
  39. /*--------------------------------------------------------------------------*/
  40. /*          Compilation Parameters for Flexibility and Portability          */
  41.  
  42. /* modify this line to allow for machine dependencies */
  43. /*#define    SUN*/
  44. /**IMPORTANT** this is now in the in the makefile */
  45.  
  46. /* modify this line for buffered/unbuffered i/o */
  47. #define    DF_BUFFIO
  48.  
  49. /* modify this line for dynamic/static memory allocation */
  50. #define    DF_DYNAMIC
  51.  
  52. /* modify this line if structures cannot be read/written as is */
  53. #undef    DF_STRUCTOK        /* leave it this way - hdfsh expects it */
  54.  
  55. /* Current version number */
  56. #define    DFVERSION   2.78
  57.  
  58. /*--------------------------------------------------------------------------*/
  59. /*                              MT/NT constants                             */
  60. /*      four MT nibbles represent int, float, double, uchar                 */
  61. #define    DFMT_SUN        0x1111
  62. #define    DFMT_ALLIANT    0x1111
  63. #define    DFMT_IRIS4      0x1111
  64. #define    DFMT_UNICOS     0x3331
  65. #define    DFMT_CTSS       0x3331
  66. #define    DFMT_VAX        0x2221
  67. #define    DFMT_PC         0x4144    /* note byte swapping ??? */
  68.                 /* check this... */
  69. #define    DFMT_MAC        0x1111
  70. #define DFMT_SUN386    0x1444
  71.  
  72. #define    DFNT_VERSION    1    /* current version of NT info */
  73.  
  74. /* type info codes */
  75. #define    DFNT_UINT       1
  76. #define    DFNT_INT        2
  77. #define    DFNT_UCHAR      3
  78. #define    DFNT_CHAR       4
  79. #define    DFNT_FLOAT      5
  80. #define    DFNT_DOUBLE     6
  81.  
  82. /* class info codes for int */
  83. #define    DFNTI_MBO       1    /* Motorola byte order 2's compl */
  84. #define    DFNTI_VBO       2    /* Vax byte order 2's compl */
  85. #define    DFNTI_IBO       4    /* Intel byte order 2's compl */
  86.  
  87. /* class info codes for float */
  88. #define    DFNTF_IEEE      1    /* IEEE format */
  89. #define    DFNTF_VAX       2    /* Vax format */
  90. #define    DFNTF_CRAY      3    /* Cray format */
  91. #define    DFNTF_PC        4    /* PC floats - flipped IEEE */
  92.  
  93. /* class info codes for char */
  94. #define    DFNTC_BYTE      0    /* bitwise/numeric field */
  95. #define    DFNTC_ASCII     1    /* ASCII */
  96. #define    DFNTC_EBCDIC    5    /* EBCDIC */
  97.  
  98. /* array order */
  99. #define    DFO_FORTRAN     1    /* column major order */
  100. #define    DFO_C           2    /* row major order */
  101.  
  102. /*--------------------------------------------------------------------------*/
  103. /*                      Machine dependencies                                */
  104. #ifdef PC
  105. #ifndef O_RDONLY
  106. #include <fcntl.h>
  107. #define    L_INCR  1
  108. #endif /*O_RDONLY*/
  109. #define    int16 int
  110. #define    uint16 unsigned int
  111. #define    int32 long int
  112. #define    float32 double
  113. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  114. #undef DF_STRUCTOK                  /* structure writing will not work on PC */
  115. #undef DF_BUFFIO                    /* unbuffered i/o is faster */
  116. long longswap();                    /* provided elsewhere */
  117.  
  118.     /* in the next 3 lines, p is recast so right number of bytes passed */
  119.     /* ### Note that all calls modify p.  Need to use temporary ptr */
  120. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  121. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  122. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  123.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  124. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  125. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  126. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  127.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  128. #define    DF_CREAT(name, prot) creat(name, prot)
  129. #define    DF_MT   DFMT_PC
  130. #endif /*PC*/
  131.  
  132.  
  133. #ifdef UNICOS
  134. #ifndef O_RDONLY
  135. #include <sys/fcntl.h>              /* for unbuffered i/o stuff */
  136. #define    L_INCR  1
  137. #endif /*O_RDONLY*/
  138. #define    int16 int
  139. #define    uint16 int
  140. #define    int32 int
  141. #define    float32 float
  142. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  143. #undef DF_STRUCTOK          /* cannot directly read/write structures */
  144. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  145. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  146. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  147. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  148.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  149. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  150. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  151. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  152.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  153. #define    DF_CREAT(name, prot) creat(name, prot)
  154. #define    DF_MT   DFMT_UNICOS
  155. #endif /*UNICOS*/
  156.  
  157.  
  158. #ifdef SUN
  159. #if ! defined mc68010 && ! defined mc68020 && ! defined mc68030
  160. #undef DF_STRUCTOK
  161. #endif
  162. #include <sys/file.h>               /* for unbuffered i/o stuff */
  163. #define    int16 short
  164. #define    uint16 unsigned short
  165. #define    int32 long
  166. #define    float32 float
  167. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  168. #ifndef DF_STRUCTOK
  169. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  170. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  171. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  172.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  173. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  174. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  175. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  176.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  177. #endif /*DF_STRUCTOK*/
  178. #define    DF_CREAT(name, prot) creat(name, prot)
  179. #define    DF_MT   DFMT_SUN
  180. #endif /*SUN*/
  181.  
  182. #ifdef SUN386
  183. #undef DF_STRUCTOK
  184. #include <sys/file.h>               /* for unbuffered i/o stuff */
  185. #define    int16 short
  186. #define    uint16 unsigned short
  187. #define    int32 long
  188. #define    float32 float
  189. #define    DFmovmem(from, to, len) memcpy(to, from, len)
  190. #ifndef DF_STRUCTOK
  191. #define    UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  192. #define    INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  193. #define    INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  194.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  195. #define    UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  196. #define    INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  197. #define    INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  198.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  199. #endif /*DF_STRUCTOK*/
  200. #define    DF_CREAT(name, prot) creat(name, prot)
  201. #define    DF_MT   DFMT_SUN386
  202. #endif /* SUN386 */
  203.  
  204. #ifdef ALLIANT
  205. #include <sys/file.h>               /* for unbuffered i/o stuff */
  206. #define    int16 short
  207. #define    uint16 unsigned short
  208. #define    int32 long
  209. #define    float32 float
  210. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  211. #ifndef DF_STRUCTOK
  212. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  213. #define    INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  214. #define    INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  215.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  216. #define    UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  217. #define    INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  218. #define    INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  219.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  220. #endif /*DF_STRUCTOK*/
  221. #define    DF_CREAT(name, prot) creat(name, prot)
  222. #define    DF_MT   DFMT_ALLIANT
  223. #endif /*ALLIANT*/
  224.  
  225.  
  226. #ifdef IRIS4
  227. #undef DF_STRUCTOK
  228. #include <sys/types.h>
  229. #include <sys/file.h>               /* for unbuffered i/o stuff */
  230. #define    int16 short
  231. #define    uint16 unsigned short
  232. #define    int32 long
  233. #define    float32 float
  234. #define    DFmovmem(from, to, len) bcopy(from, to, len)
  235. #ifndef DF_STRUCTOK
  236. #define    UINT16READ(p, x)    { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  237. #define INT16READ(p, x)     { x = (*p++)<<8; x |= (*p++) & 255; }
  238. #define INT32READ(p, x)     { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  239.                                 x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  240. #define UINT16WRITE(p, x)   { *p++ = (x>>8) & 255; *p++ = x & 255; }
  241. #define INT16WRITE(p, x)    { *p++ = (x>>8) & 255; *p++ = x & 255; }
  242. #define INT32WRITE(p, x)    { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;   \
  243.                                 *p++ = (x>>8) & 255; *p++ = x & 255; }
  244. #endif /*DF_STRUCTOK*/
  245. #define DF_CREAT(name, prot) creat(name, prot)
  246. #define DF_MT   DFMT_IRIS4
  247. #endif /*IRIS4*/
  248.  
  249.  
  250. #ifdef MAC
  251. #include <memory.h>             /* malloc stuff for MPW 3.0 */
  252. #include <fcntl.h>              /* unbuffered IO stuff for MPW 3.0 */
  253. #ifdef THINK_C                  /* for LightSpeed C */
  254. #include <unix.h>
  255. #else /*THINK_C                   MPW, possibly others */
  256. #include <Files.h>              /* for unbuffered i/o stuff */
  257. #endif /*THINK_C*/
  258. #define    DF_CAPFNAMES            /* fortran names are in all caps */
  259. #define DF_DYNAMIC        /* use dynamic allocation */
  260. #define int16 short
  261. #define uint16 unsigned short
  262. #define int32 long
  263. #define float32 float
  264. #ifdef THINK_C                   /* LightSpeed C does not have memcpy */
  265. #define DFmovmem(from, to, len) DFImemcopy(from, to, len)
  266. #else /*THINK_C*/
  267. #define DFmovmem(from, to, len) memcpy(to, from, len)
  268. #endif /*THINK_C*/
  269. #define malloc(x)   NewPtr((Size)   (x))    /* don't use malloc on the Mac */
  270. #define free(x)     DisposPtr((Ptr) (x))    /* don't use free on the Nac   */ 
  271. #undef DF_STRUCTOK
  272. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  273. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  274. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  275.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  276. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  277. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  278. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  279.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  280. #define DF_CREAT(name, prot) open(name, O_WRONLY|O_TRUNC|O_CREAT)
  281. #define DF_MT   DFMT_MAC
  282. /*#define DF_PROTO*/        /* need prototype declarations */
  283. #endif /*MAC*/
  284.  
  285. #ifdef VMS
  286. #undef DF_BUFFIO                /* use only unbuff i/o - buff doesn't work! */
  287. #ifndef DFopen                  /* avoid double includes */
  288. #include "dfivms.h"
  289. #endif /*DFopen*/
  290. #undef DF_STRUCTOK
  291. #define DF_CAPFNAMES            /* fortran names are in all caps */
  292. #include <file.h>               /* for unbuffered i/o stuff */
  293. #define int16 short
  294. #define uint16 unsigned short
  295. #define int32 long
  296. #define float32 float
  297. #define DFmovmem(from, to, len) memcpy(to, from, len)
  298. #ifndef DF_STRUCTOK
  299. #define UINT16READ(p, x) { x = ((*p++) & 255)<<8; x |= (*p++) & 255; }
  300. #define INT16READ(p, x) { x = (*p++)<<8; x |= (*p++) & 255; }
  301. #define INT32READ(p, x) { x = (*p++)<<24; x|=((*p++) & 255)<<16;    \
  302.             x|=((*p++) & 255)<<8; x|=(*p++) & 255; }
  303. #define UINT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  304. #define INT16WRITE(p, x) { *p++ = (x>>8) & 255; *p++ = x & 255; }
  305. #define INT32WRITE(p, x) { *p++ = (x>>24) & 255; *p++ = (x>>16) & 255;  \
  306.             *p++ = (x>>8) & 255; *p++ = x & 255; }
  307. #endif /*DF_STRUCTOK*/
  308. #define DF_CREAT(name, prot) creat(name, prot)
  309. #define DF_MT   DFMT_VAX
  310. #endif /*VMS*/
  311.  
  312.  
  313.  
  314. /*--------------------------------------------------------------------------*/
  315. /*                      Flexibility parameters                              */
  316.  
  317. #ifdef DF_BUFFIO            /* set all calls to do buffered I/O */
  318. #define DF_OPEN(x,y) fopen(x,y)
  319. #define DF_CLOSE(x) fclose(x)
  320. #define DF_SEEK(x,y,z) fseek(x,y,z)
  321. #define DF_SKEND(x,y,z) fseek(x,y,z)
  322. #define DF_TELL(x) ftell(x)
  323. #define DF_READ(a,b,c,d) fread(a,b,c,d)
  324. #define DF_WRITE(a,b,c,d) fwrite(a,b,c,d)
  325. #define DF_FLUSH(a) fflush(a)
  326. #ifdef PC
  327. #define DF_RDACCESS "rb"
  328. #define DF_WRACCESS "rb+"
  329. #else /*PC*/
  330. #define DF_RDACCESS "r"
  331. #define DF_WRACCESS "r+"
  332. #endif /*PC*/
  333.  
  334. #else /*DF_BUFFIO         unbuffered i/o */
  335. #define DF_OPEN(x,y) open(x,y)
  336. #define DF_CLOSE(x) close(x)
  337. #define DF_SEEK(x,y,z) lseek(x,y,z)
  338. #define DF_SKEND(x,y,z) lseek(x,-1*y,z)
  339. #define DF_TELL(x) lseek(x,0L,1)
  340. #define DF_READ(a,b,c,d) read(d,a,b*c)
  341. #define DF_WRITE(a,b,c,d) write(d,a,b*c)
  342. #define DF_FLUSH(a)                             /* no need to flush */
  343. #ifdef PC
  344. #define DF_RDACCESS O_RDONLY | O_RAW
  345. #define DF_WRACCESS O_RDWR | O_RAW
  346. #else /*PC*/
  347. #define DF_RDACCESS O_RDONLY
  348. #define DF_WRACCESS O_RDWR
  349. #endif /*PC*/
  350. #endif /*DF_BUFFIO*/
  351.  
  352.  
  353.     /* if not allocating memory dynamically, need buffer for compression */
  354. #ifndef DF_DYNAMIC
  355. #define DF_TBUF
  356. #define DF_TBUFSZ    10000    /* buffer size */
  357. #endif /*DF_DYNAMIC*/
  358.  
  359.     /* if reading/writing structures not ok, need buffer for conversion */
  360. #ifndef DF_TBUF
  361. #ifndef DF_STRUCTOK
  362. #define DF_TBUF
  363. #define DF_TBUFSZ    256    /* buffer size can be smaller */
  364. #endif /*DF_STRUCTOK*/
  365. #endif /*DF_TBUF*/
  366.  
  367.     /* set buffer size */
  368. #ifdef DF_TBUF
  369. #ifndef DFMASTER
  370. extern
  371. #endif /*DFMASTER*/
  372.     char DFtbuf[DF_TBUFSZ];
  373. #endif /*DF_TBUF*/
  374.  
  375. /*--------------------------------------------------------------------------*/
  376. /*                          Size parameters                                 */
  377. #define DF_MAXDFS           32  /* How many DF's can be open at once */
  378. #define DF_DEFAULTDDS       16  /* How many DD's a file has by default */
  379. #define DF_MAXFNLEN         256 /* maximum length of filename parameters */
  380.  
  381. #ifndef MAC
  382. char *strncpy();
  383. char *strcpy();
  384. char *malloc();
  385. char *memcpy();
  386. #endif /*MAC*/
  387.  
  388. #endif /*DF_MAGICK*/
  389.